<?php

namespace Music\FrontendBundle\Component\Authentication\Handler;

use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Router;
use FOS\UserBundle\FOSUserEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use FOS\UserBundle\Event\FormEvent;

class RegisterSuccessHandler implements EventSubscriberInterface
{
    protected $router;

    public function __construct(Router $router)
    {
        $this->router      = $router;
    }

    /**
     * {@inheritDoc}
     */
    public static function getSubscribedEvents()
    {
        return array(
            FOSUserEvents::REGISTRATION_SUCCESS => 'onRegisterSuccess',
        );
    }

    public function onRegisterSuccess(FormEvent $event)
    {
        $response = new RedirectResponse($this->router->generate('music_frontend_default_index'));
        return $event->setResponse($response);
    }
}
